<?php $this->load->module('mobile/index/header', $common);?>
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/main.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/dialog.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/base.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/index.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/line.css" />
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/mobilecommon.js"></script>
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/slider.js"></script>
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/dialog.js"></script>
<div class="content">
    <div class="head-memu-box">
        <ul class="head-memu-list">
            <li class="head-menu-item"><a href="<?php echo $line_url;?>">线路</a></li>
            <li class="head-menu-item head-menu-item-on"><a href="<?php echo $ticket_url;?>">景区</a></li>
            <li class="head-menu-item"><a href="<?php echo $rent_url;?>">租车</a></li>
         </ul>
    </div>
    <div id="js-datalist">
        <?php if(!$datalist){?>
            <a>
                <div class="list-item fn-clear">
                    <div class="info">
                        <h5>暂无收藏</h5>
                        <div class="i-note"></div>
                    </div>
                </div>
            </a>
        <?php }?>

        <div class="fav-list-wrap" >
            <ul id="js-fav-wrap" class="fav-list">
                 <?php if($datalist){?>
                     <?php foreach ($datalist as $v): ?>
                         <li class="fav-list-item">
                            <a href="<?php echo $v['link'] ?>">
                                <div class="item-img">
                                   <img src="<?php echo URLPIC.$v['cover'] ?>">
                                </div>
                                 <div class="item-main">
                                  <h1>[<?php echo $v['title'] ?>]</h1>
                                  <span class="item-button">立即查看</span>
                                 </div>
                            </a>
                            <div class="item-delete js-del-fav" data-id="<?php echo $v['id'];?>">
                                <i></i>
                            </div>
                        </li>
                     <?php endforeach ;?>
                 <?php }?>
            </ul>
        </div>
        <?php if($datalist){?>
            <a href="javascript:;" class="btn-grey btn" id="js-load-more">加载更多</a>
        <?php }?>
    </div>
</div>
<?php $this->load->module('mobile/index/footer', $common);?>
<script type="text/javascript">
    var URLPRE = '<?php echo URLPRE?>';

    $(function(){

        $('#js-fav-wrap').find('img').error(function(){
                $(this).attr('src',URLPRE+'static/public/images/nophoto.jpg');
        })

        var slid = $("#sliderimg").slider({
            loop: true
        });
        var page = <?php echo $page+1;?>;
        var url = '<?php echo site_url('mobile/member/favourite_list');?>';
        var del_url = '<?php echo site_url('mobile/member/delete_favourite');?>';
        $(window).scroll(function(){

            totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
            if ($(document).height() <= totalheight) {
                var $js_load_more = $('#js-load-more');
                $js_load_more.text('加载中...');

                $.get(url+(url.indexOf('?')!=-1 ?'&':'/?')+'isajax=1&type=2&page='+page, function(data){

                    if(data.length>0){
                        var html = '';
                        for(var i =0; i<data.length; i++){
                            var item = data[i];
                            html += '<li class="fav-list-item">'+
                                '<a href="'+item.link+'">'+
                                '<div class="item-img">'+
                                '<img src="<?php echo URLPIC?>'+item.cover+'">'+
                                '</div>'+
                                '<div class="item-main">'+
                                '<h1>'+item.title+'</h1>'+
                                '<span class="item-button">立即查看</span>'+
                                '</div>'+
                                '</a>'+
                                '<div class="item-delete js-del-fav" data-id="'+item.id+'">'+
                                '<i></i>'+
                                '</div>'+
                                '</li>';
                        }
                        $('#js-fav-wrap').append(html);
                        page ++;
                    }else{

                        $.dialog({
                            style:'tip',
                            width:200,
                            closeTime:1000,
                            content: '<p style="text-align: center">没有更多了</p>'
                        }).open();
                    }
                    $js_load_more.text('加载完毕');
                },'json');
            }
        });

        $('.js-del-fav').click(function(){

            var data_id = $(this).data('id');
            that =$(this);
            $.get(del_url+(url.indexOf("?") > -1 ? "&" : "?")+'id='+data_id, function(data){

                if(data.status.length>0){
                    $.dialog({
                        style:'tip',
                        width:200,
                        closeTime:1000,
                        content: '<p style="text-align: center">'+data.msg+'</p>'
                    }).open();
                    if(data.status=='1'){

                        that.closest('li').remove();
                    }
                }
            },'json');
        });

    });
</script>